package com.jjb.www.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;

import com.hjq.bar.TitleBar;
import com.hjq.base.BaseAdapter;
import com.hjq.base.BaseDialog;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.http.api.CurriculumSortApi;
import com.jjb.www.http.api.MeCurriculumApi;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.ui.adapter.MeCurriculumAdapter;
import com.jjb.www.ui.dialog.MessageDialog;
import com.jjb.www.ui.fragment.CourseListFragment;
import com.jjb.www.widget.CommonRefreshView;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/03/01
 *    desc   : 我的课程
 */
public class MeCurriculumActivity extends AppActivity implements BaseAdapter.OnItemClickListener {
    private TitleBar mTitleBar;
    private WrapRecyclerView mMeRcv;
    private MeCurriculumAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_me_curriculum;
    }

    @Override
    protected void initView() {
        mTitleBar = findViewById(R.id.titleBar);
        mMeRcv = findViewById(R.id.me_rcv);
        mMeRcv.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new MeCurriculumAdapter(getContext());
        adapter.setOnItemClickListener(this);
        mMeRcv.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        EasyHttp.get(this)
                .api(new MeCurriculumApi())
                .request(new HttpCallback<HttpList<MeCurriculumApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpList<MeCurriculumApi.Bean> data) {
                        adapter.setData(data.getData());
                        mTitleBar.setTitle("我的课程("+data.getData().size()+")");
                    }

                });
    }

    @Override
    public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
        if (adapter.getItem(position).getTime_status()==0){
            new MessageDialog.Builder(getActivity())
                    // 标题可以不用填写
//                    .setTitle("")
                    // 内容必须要填写
                    .setMessage("课程播放权限已到期,如果继续学习,请进入学习页面重新购买")
                    // 确定按钮文本
                    .setConfirm("确定")
                    // 设置 null 表示不显示取消按钮
                    .setCancel(null)
                    // 设置点击按钮后不关闭对话框
//                    .setAutoDismiss(false)
                    .setListener(new MessageDialog.OnListener() {

                        @Override
                        public void onConfirm(BaseDialog dialog) {
                        }

                        @Override
                        public void onCancel(BaseDialog dialog) {
                        }
                    })
                    .show();
        }
    }
}